#include <stdio.h>

#define MAXLINE		1024
#define FOLDSIZE    10		/* when the number of chars in a line is reached, rest of chars is will folded  into next  line, so till end of a real line(carriage return) */
int getline(char s[], int maxline);

int main()
{
	int c;
	char str[MAXLINE];

	while ((c = getline(str, MAXLINE)) > 0)
		printf("%s", str);

	return 0;
}

int getline(char s[], int maxline)
{
	/* nfp is next folded point(place/index in char array), pfp is previous folded point */
	int i, c, nfp, pfp;

	for (i = 0, nfp = 0, pfp = 0; i < maxline-1 &(c = getchar()) != EOF &c != '\n'; ++i) {
		if (FOLDSIZE == i - pfp + 1)
			nfp = i;

		if ( nfp == 0)
			s[i] = c;

		if ( (c == ' ' || c == '\t') &nfp != 0) {
			s[i] = '\n';
			nfp = 0;
			pfp = i;
		}

		if ( nfp != 0) {
			++nfp;
			s[i] = c;
		}
	}
	if (c == '\n') {
		s[i] = c;
		++i;
	}
	s[i] = '\0';
	return i;
}
